//
//  MTicketService.m
//  NeusoftHBSJSober
//
//  Created by Apple-21 on 15/11/11.
//  Copyright (c) 2015年 com.neusoftsober. All rights reserved.
//

#import "MTicketService.h"
#import "MFriendTicketModel.h"
#import "MSalemanModel.h"
#define FRIEND_LIST_URL  [NSString stringWithFormat:@"%@",@"api/Share/Friend/Upgrade"]
//  get merchant_info  get
#define MERCHANT_LIST_URL  [NSString stringWithFormat:@"%@",@"api/CashWhenFee"]
// 获取等级 getpath  path拼接cash,codeid    参数codeID
#define CASH_COPON_LEVEL  [NSString stringWithFormat:@"%@",@"api/Share/Friend/Level/"]
@implementation MTicketService
+(id)sharedClient
{
    static dispatch_once_t pred;
    static MTicketService *shared_instance=nil;
    dispatch_once(&pred, ^{
        shared_instance=[[self alloc] init];
        shared_instance.client=[self sharedHTTPClient];
    });
    return  shared_instance;
}

- (void)getFriendListWithUserID:(NSString *)userID completion:(GetFriendListCompletionHandle)success failure:(GetFriendListCompletionError)failure {

    NSDictionary *parmas = [[NSDictionary alloc]initWithObjectsAndKeys:userID,@"userid", nil];
    
    [self.client getPath:FRIEND_LIST_URL parameters:parmas success:^(AFHTTPRequestOperation *operation, id responseObject){
    
        id JSON = ((AFJSONRequestOperation *)operation).responseJSON;
        
        success([[MFriendTicketHttpResult alloc]getFriendListWithArray:JSON]);
        
    } failure:^(AFHTTPRequestOperation *operation, NSError *error){
    
        failure(@"网络异常");
    }];
}
// salemanuserid    codeID
- (void)getMerchantInfoWithSalemanUserID:(NSString *)merchantID completion:(GetSalemanInfoCompletionHandle)success failure:(GetSalemanInfoCompletionError)failure {

    NSDictionary *parmas = [[NSDictionary alloc]initWithObjectsAndKeys:merchantID,@"salemanuserid", nil];
    
    [self.client getPath:MERCHANT_LIST_URL parameters:parmas success:^(AFHTTPRequestOperation *operation, id responseObject){
        
        id JSON = ((AFJSONRequestOperation *)operation).responseJSON;
       
        success([[MSalemanHttpResult alloc]getSalemanInfomationWithJson:JSON]);
        
    } failure:^(AFHTTPRequestOperation *operation, NSError *error){
    
    }];
}
- (void)getCashCoponWithCodeID:(NSString *)codeID completion:(GetCashCoponCompletionHandle)success failure:(GetCashCoponCompletionError)failure {

    NSString *path = [NSString stringWithFormat:@"%@%@",CASH_COPON_LEVEL,codeID];
    [self.client getPath:path parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject){
    
        id JSON = ((AFJSONRequestOperation *)operation).responseJSON;
        
        NSMutableArray *data = [[NSMutableArray alloc]initWithObjects:JSON[@"CurrentMoney"],JSON[@"FriendCount"],JSON[@"Levels"], nil];
        success(data);
        
        
    } failure:^(AFHTTPRequestOperation *operation, NSError *error){
    
    }];
}
@end
